package com.github.caijh.mall.front.controller;


import java.util.HashMap;
import java.util.List;

import com.github.caijh.framework.web.controller.BaseController;
import com.github.caijh.mall.common.CommonResult;
import com.github.caijh.mall.common.PageParams;
import com.github.caijh.mall.constants.Constants;
import com.github.caijh.mall.front.response.IndexInfoResponse;
import com.github.caijh.mall.front.response.IndexProductBannerResponse;
import com.github.caijh.mall.front.service.IndexService;
import com.github.caijh.mall.wechat.model.WechatShareInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("IndexController")
@RequestMapping("api/front")
@Api(tags = "首页")
public class IndexController extends BaseController {

    @Autowired
    private IndexService indexService;

    /**
     * 首页产品的轮播图和产品信息
     *
     * @param type       类型
     * @param pageParams PageParams
     * @return IndexProductBannerResponse
     */
    @ApiOperation(value = "首页产品的轮播图和产品信息")
    @GetMapping(value = "/groom/list/{type}")
    @ApiImplicitParam(name = "type", value = "类型 【1 精品推荐 2 热门榜单 3首发新品 4促销单品】", dataTypeClass = Integer.class, required = true)
    public CommonResult<IndexProductBannerResponse> getProductBanner(@PathVariable(value = "type") int type, PageParams pageParams) {
        if (type < Constants.INDEX_RECOMMEND_BANNER || type > Constants.INDEX_BENEFIT_BANNER) {
            return CommonResult.validateFailed();
        }
        return CommonResult.success(indexService.getProductBanner(type, pageParams));
    }

    /**
     * 首页数据
     *
     * @return IndexInfoResponse
     */
    @ApiOperation(value = "首页数据")
    @GetMapping(value = "/index")
    public CommonResult<IndexInfoResponse> getIndexInfo() {
        return CommonResult.success(indexService.getIndexInfo());
    }

    /**
     * 热门搜索
     *
     * @return {@code List<HashMap<String, Object>>}
     */
    @ApiOperation(value = "热门搜索")
    @GetMapping(value = "/search/keyword")
    public CommonResult<List<HashMap<String, Object>>> hotKeywords() {
        return CommonResult.success(indexService.hotKeywords());
    }

    /**
     * 分享配置
     *
     * @return WechatShareInfo
     */
    @ApiOperation(value = "分享配置")
    @GetMapping(value = "/share")
    public WechatShareInfo share() {
        return indexService.getShareConfig();
    }

}



